
#include "SDL.h"
#include "SDL_opengl.h"

const GLchar *g_src_fs =
    "float t;"
    "void main(){"
        "t=gl_TexCoord[0].s*.001;"
        "gl_FragColor=vec4(.5+.5*sin(t));"
    "}";

int begin() {
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    return 0;
}

int update() {
    glClear(GL_COLOR_BUFFER_BIT);
    return 0;
}

int end() {
    return 0;
}

int run() {
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
    SDL_WindowID win = SDL_CreateWindow("test6", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
    SDL_GL_CreateContext(win);

    int result = 0;

    if (begin() < 0) {
        result = -1;
    }

    while (result == 0) {

        SDL_Event evt;
        while (SDL_PollEvent(&evt)) {
            if (evt.type == SDL_KEYDOWN || evt.type == SDL_QUIT) {
                result = 1;
            }
        }

        if (update() < 0) {
            result = -1;
        }
        SDL_GL_SwapWindow(win);
    }

    if (end() < 0) {
        result = -1;
    }
    return result;
}

int main() {
    int r = run();
    SDL_Quit();
    return r;
}
